﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using RedBit.UserVoice.Services;
using RedBit.UserVoice.OAuth;
using System.Linq;

namespace RedBit.UserVoice.Helpers
{
    public class UVUserHelper
    {
        private static OAuthUser m_currentUser = null;

        public static OAuthUser CurrentUser { get { return m_currentUser; } }

        public static void Initialize()
        {
            UVUserService.GetCurrentUser((user) => 
                {
                    m_currentUser = user.Model;
                });
        }

        public static void Initialize(Action<OAuthUser> callback)
        {
            UVUserService.GetCurrentUser((user) =>
            {
                m_currentUser = user.Model;
                callback(m_currentUser);
            });
        }

        public static int GetCurrentVotesForSuggestion(string forumId, string suggestionId)
        {
            
            var ss = CurrentUser.SupportedSuggestions.Where(supsug => supsug.Id == suggestionId && supsug.ForumId == forumId);

            if (ss == null || ss.Count() == 0)
                return 0;
            else
                return ss.FirstOrDefault().Votes;

        }
    }
}
